var config = require('./config.json');
var _ = require('lodash');
var crypto = require('crypto');

module.exports = function signature(opts) {

  var signature = opts.signature;
  var timeStamp = opts.timestamp;
  var nonce = opts.nonce;
  var echostr = opts.echostr;
  var token = config.token;

  var tmp = [token, timeStamp, nonce];
  tmp = _.sortBy(tmp, function(n) {
    return n;
  });
  var newStr = tmp.join("");
  if (crypto.createHash('sha1').update(newStr).digest('hex') === signature && echostr) {
    return echostr;
  }

  return false;
}
